<?php
namespace app\api\model\wanlshop\groups;

use app\api\model\wanlshop\Shop;
use think\Model;
use traits\model\SoftDelete;

class OrderGoods extends Model
{
    use SoftDelete;

    // 表名
    protected $name = 'wanlshop_groups_order_goods';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';


    public function getMarketPriceAttr($value,$data){
        if(isset($data['market_price']) && $data['market_price'] !== '' && isset($data['shop_id']) && $data['shop_id'] > 0){
            $isChina = Shop::where(['id'=>$data['shop_id']])->value('is_china');
            if($isChina == 1 && isUrlRussian()){
                $mgRate = get_addon_config('wanlshop')['config']['mg_rate'];
                $value = $data['market_price'] * $mgRate;
            }
        }

        return $value;
    }
}
